<template>
  <div class="hospitalStockTable">
    <el-table
      ref="stockTable"
      :header-cell-style="handleCellStyle"
      :data="stockTable"
    >
      <el-table-column label="门店" :show-overflow-tooltip="true" prop="storeName" />
      <el-table-column label="商品" :show-overflow-tooltip="true" prop="goodsName" />
      <el-table-column label="规格" :show-overflow-tooltip="true" prop="skuName" />
      <el-table-column label="医院库存" prop="equIdArray" width="400">
        <template slot-scope="scope">
          <hospital-stock-code v-if="scope.row.equIdArray" ref="hospitalStock" :codes="scope.row.equIdArray" :store-id="scope.row.storeId" :goods-id="scope.row.goodsId" :sku-id="scope.row.skuId" style="margin-bottom: 20px;" />
          <hospital-stock-code v-if="!scope.row.equIdArray" ref="hospitalStock" :store-id="scope.row.storeId" :goods-id="scope.row.goodsId" :sku-id="scope.row.skuId" style="margin-bottom: 20px;" />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import HospitalStockCode from '@/components/HospitalStockCode'

export default {
  name: 'Index',
  components: { HospitalStockCode },
  data() {
    return {
      stockTable: []
    }
  },
  methods: {
    setData(list) {
      this.stockTable = list
      this.$nextTick(() => {
        console.log(this.$refs.hospitalStock.codes)
      })
      console.log(list)
    },
    getData() {
      if (this.stockTable.length > 1) {
        this.stockTable.forEach(item => {
          this.$refs.hospitalStock.forEach(inf => {
            if (item.storeId == inf.storeId && item.goodsId == inf.goodsId && item.skuId == inf.skuId && inf.getData()) {
              item.equIdArray = inf.getData()
            }
          })
        })
      } else if (this.stockTable.length == 1) {
        if (this.stockTable[0].storeId == this.$refs.hospitalStock.storeId && this.stockTable[0].goodsId == this.$refs.hospitalStock.goodsId && this.stockTable[0].skuId == this.$refs.hospitalStock.skuId && this.$refs.hospitalStock.getData()) {
          this.stockTable[0].equIdArray = this.$refs.hospitalStock.getData()
        }
      }
      console.log(this.stockTable)
      return this.stockTable
    },
    handleCellStyle({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return 'background:#f3f3f3'
      } else {
        return ''
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
